package washcard;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardList {
    public static final String [] SUIT = {"♦" , "♣", "♥" , "♠"};

    public static List<Card> buyCard(){
        List<Card> cardList = new ArrayList<>();
        //为牌组中添加元素
        for(int i = 0; i < SUIT.length; i++){
            for(int j = 1; j <= 13; j++){
                Card card = new Card(SUIT[i],j);
                cardList.add(card);
            }
        }
        return cardList;
    }
    //洗牌
    public static void washCard(List<Card> card){
        Random random = new Random();
        for(int i = card.size() - 1; i > 0; i--) {
            int j = random.nextInt(i);
            swap(card, i, j);
        }
    }
    //交换随机位置和i位置的牌
    public static void swap(List<Card> card, int i , int j){
        Card tmp = card.get(i);
        card.set(i,card.get(j));
        card.set(j,tmp);
    }

    //摸牌
    public static List<List<Card>> play(){
        List<Card> list = buyCard();
        washCard(list);
        List<List<Card>> hand = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for(int i = 0; i < 5; i++){
            for(int j = 0; j < 3; j++){
                Card card = list.remove(0);
                hand.get(j).add(card);
            }
        }
        return hand;
    }
    public static void main(String[] args) {
        System.out.println(play());
    }
}
